<?php
	/*
		this file displays the projects owned by the current user
	*/
	require_once("../functions.php");
	if(!isLoggedIn()){
		header("location:index.php?message=".urlencode("Please login first."));
		die();
	}
	
	$con = connectToDB();
	
	$uname = $_SESSION["username"];
	$result = mysql_query("select p.id,p.name,p.dateCreated,p.dateModified,p.description from project p,user u where p.user_id = u.id and p.isValid=true and u.username='$uname' order by dateModified desc");
	$nrows = mysql_num_rows($result);
?>

<h2 style="color:#3366CC">Projects</h2>
<br />
<?php
	if($nrows>0){
		echo "<p>Here are the projects made by you.</p><br /><ul>";
		while($row = mysql_fetch_array($result)){
			echo "<li><a href='javascript:openProject($row[id])'>$row[name]</a></li>";
		}
		echo "</ul>";
	}else{
		echo "There are no projects. Create a <a href='javascript:newProject()'>new</a> project?";
	}
	
	mysql_free_result($result);
?>